﻿#define _CRT_SECURE_NO_WARNINGS 1//写一个函数，判断一个字符串是否为另外一个字符串旋转之后的字符串。
#include<stdio.h>
#include<string.h>
int left_judge(char a[], char b[], int len)//左旋转
{
	int i = 0;
	int j = 0;
	for (i = 0; i < len; i++)//左旋转字符串的长度次
	{
		char temp = a[0];
		for (j = 1; j <= len - 1; j++)
		{
			a[j - 1] = a[j];
		}
		a[j - 1] = temp;
		if (strcmp(a, b) == 0)//比较字符串a和b是否相同
		{
			return 1;
		}
	}
	return -1;
}
int right_judge(char a[], char b[], int len)//右旋转
{
	int i = 0;
	int j = 0;
	for (i = 0; i < len; i++)//右旋转字符串的长度次
	{
		char temp = a[len - 1];
		for (j = len - 2; j >= 0; j--)
		{
			a[j + 1] = a[j];
		}
		a[0] = temp;
		if (strcmp(a, b) == 0)//比较字符串a和b是否相同
		{
			return 1;
		}
	}
	return -1;
}
int main()
{
	char a[10] = { 0 };
	char b[10] = { 0 };
	printf("请输入字符串：a= ");
	scanf("%s", &a);
	printf("请输入变化后的字符串b= ");
	scanf("%s", &b);
	char c[10] = { 0 };
	strcpy(c, a);
	if (strlen(a) == strlen(b))
	{
		int len = strlen(a);
		int lret = left_judge(a, b, len);
		int rret = right_judge(a, b, len);
		if (lret == 1 || rret == 1)
		{
			printf("%s是%s旋转成的字符串\n", b, c);
		}
		else
		{
			printf("%s不是%s旋转成的字符串\n", b, c);
		}
	}
	else
	{
		printf("%s不是%s旋转成的字符串\n", b, c);
	}
	return 0;
}

